ORDER.CouponModuleFix = function() {
  //------------------------------------------------------------------------------
  //订阅发布事件
  var eventAggregator = new EventAggregator();
  //判断券是否以选择
  var chooseTicketVerify = new ChooseTicketVerify();
  //选取免邮券、优惠券需要改变的状态
  var orderAmountByCoupon = new OrderAmountByCoupon(chooseTicketVerify);
  //产品仓库,获取数据
  var productRepository = new ProductRepositoryFix(chooseTicketVerify, '1');
  //事件的聚合器
  var eventController = new EventController(orderAmountByCoupon, eventAggregator, chooseTicketVerify);
  //------------------------------------------------------------------------------
  //首先我们先来实现事件聚合的功能，该功能分为2部分，1个是Event，
  //用于Handler处理器回调的代码，1个是EventAggregator用来订阅和发布Event，代码如下：
  function Event(name) {
    var handlers = [];
    this.getName = function() {
      return name;
    };
    this.addHandler = function(handler) {
      handlers.push(handler);
    };
    this.fire = function(eventArgs) {
      /* handlers.forEach(function(h) {
       h(eventArgs);
       });*/
      for (var k = 0; k < handlers.length; k++) {
        var h = handlers[k];
        h(eventArgs);
      }
    };
  }

  function EventAggregator() {
    var events = [];

    function getEvent(eventName) {
      if (events.length > 0)
        for (var k = 0; k < events.length; k++) {
          if (events[k].getName() == eventName)
            return events[k]
        }
    }

    this.publish = function(eventName, eventArgs) {
      var event = getEvent(eventName);
      if (!event) {
        event = new Event(eventName);
        events.push(event);
      }
      event.fire(eventArgs);
    };
    this.subscribe = function(eventName, handler) {
      var event = getEvent(eventName);
      if (!event) {
        event = new Event(eventName);
        events.push(event);
      }
      event.addHandler(handler);
    };
  }

//这个是一个优惠券免邮券的实例
  function Product(cardNo, cardName, useStartDate, useEndDate, useQuota, couponBatchId, cash, canUseAmount) {
    this.cardNo = function() {
      return cardNo;
    };
    this.couponUsebutton = function() {
      return "use_selected_coupon_" + cardNo;
    };
    this.couponUnusebutton = function() {
      return "unuse_selected_coupon_" + cardNo;
    };
    this.freeShipUsebutton = function() {
      return "use_selected_freeship_coupon_" + cardNo;
    };
    this.freeShipUnusebutton = function() {
      return "unuse_selected_freeship_coupon_" + cardNo;
    };
    this.couponSelectedli = function() {
      return "li_coupon_" + cardNo;
    };
    this.freeShipSelectedli = function() {
      return "li_freeship_coupon_" + cardNo;
    };
    this.cardName = function() {
      return cardName;
    };
    this.useStartDate = function() {
      return useStartDate;
    };
    this.useEndDate = function() {
      return useEndDate;
    };
    this.useQuota = function() {
      return useQuota;
    };
    this.couponBatchId = function() {
      return couponBatchId;
    };
    this.cash = function() {
      return cash;
    };
    this.canUseAmount = function() {
      return canUseAmount;
    }
  }

//选取免邮券、优惠券需要改变的状态
  function OrderAmountByCoupon(chooseTicketVerify) {
    this.getCouponUseState = function(couponJsonStr, flag, usebutton, unusebutton, cbtnid, selectedli, way) {
      var params = "couponJsonStr=" + JSON.stringify(couponJsonStr);
      Js.sendData(sendLink.tradeservice + ORDER.API.orderAmountByCoupon, params, function(data) {
        if (data.status == '0') {
          //使用商品优惠券
          if (flag) {
            couponUsedEvent(unusebutton, cbtnid, selectedli);
          }
          //取消商品优惠券
          if (!flag) {
            cancelCouponUsedEvent(usebutton, unusebutton, cbtnid, selectedli, way);
          }
          //重新初始化乐券
          ORDER.GiftCardModule.initGiftCardAssembly();
          //重新初始化乐豆
          ORDER.PointModule.getPointInfo();
          //更新下单明细
          ORDER.AmountDetailModule.reloadAmountDetail(data);
        }
      });
    };
    this.getFreeShipCouponUseState = function(freeFreightCardJsonStr, flag, usebutton, unusebutton, cbtnid, selectedli, way) {
      var params = "freeFreightCardJsonStr=" + JSON.stringify(freeFreightCardJsonStr);
      Js.sendData(sendLink.tradeservice + ORDER.API.orderAmountByFreeFreightCard, params, function(data) {
        if (data.status == '0') {
          //使用免邮券
          if (flag) {
            couponUsedEvent(unusebutton, cbtnid, selectedli);
          }
          //取消使用免邮券
          if (!flag) {
            cancelCouponUsedEvent(usebutton, unusebutton, cbtnid, selectedli, way);
          }
          //更新下单明细
          ORDER.AmountDetailModule.reloadAmountDetail(data);
        }
      });
    };
    function couponUsedEvent(unusebutton, cbtnid, selectedli) {
      //$("#js_syyhq_btn").find(".js_title_btn").addClass("red_jianhao");
      //$("#js_syyhq_btn").find(".js_title_btn").addClass("red_jiahao");
      //$("#help_coupon").addClass("hidden");
      //$("#js_selet_coupon").addClass("hidden");
      if (!chooseTicketVerify.getCouponVerify("favorableCoupon")) {

      }
      $("#js_selected_coupon").addClass("hidden");
      if (!chooseTicketVerify.getCouponVerify("freeShipCoupon")) {
        $("#js_selected_freeshop_coupon").removeClass("hidden");
      }
      $("#" + selectedli).addClass("one_li");
      $("#" + selectedli).addClass("cur");
      $("#" + unusebutton).removeClass("hidden");
    }

    function cancelCouponUsedEvent(usebutton, unusebutton, cbtnid, selectedli, way) {
      if (way == "list") {
        $("#" + selectedli).removeClass("one_li");
        $("#" + selectedli).removeClass("cur");
        $("#" + usebutton).removeClass("hidden");
      }
      if (way == "div") {
        $("#js_syyhq_btn").find(".js_title_btn").removeClass("red_jiahao");
        $("#js_syyhq_btn").find(".js_title_btn").addClass("red_jianhao");
        $("#js_selected_coupon").addClass("hidden");
        $("#js_selected_freeshop_coupon").addClass("hidden");
        $("#js_selet_coupon").removeClass("hidden");
        $("#help_coupon").removeClass("hidden");
        $("#" + unusebutton).addClass("hidden");
        $("#" + selectedli).removeClass("one_li");
        $("#" + selectedli).removeClass("cur");
        $("#" + usebutton).removeClass("hidden");
      }
    }
  }

//判断券是否以选择
  function ChooseTicketVerify() {
    var _this = this;
    var favorableCoupon = [];
    var freeShipCoupon = [];
    this.getChooseCouponData = function() {
      return {
        'favorableCoupon': favorableCoupon,
        'freeShipCoupon': freeShipCoupon
      }
    };
    this.getCouponVerify = function(favorableORfreeShip) {
      switch (favorableORfreeShip) {
        case "favorableCoupon" :
          return favorableCoupon.length == 0;
        case "freeShipCoupon" :
          return freeShipCoupon.length == 0;
      }
    };
    this.chooseCouponVerify = function(favorableORfreeShip, coupon) {
      switch (favorableORfreeShip) {
        case "favorableCoupon" :
          if (_this.getCouponVerify("favorableCoupon")) {
            if (coupon != "") {
              favorableCoupon.push(coupon);
            }
            return true;
          } else {
            alert("每个订单只可以使用一次优惠券");
            return false;
          }
        case "freeShipCoupon" :
          if (_this.getCouponVerify("freeShipCoupon")) {
            if (coupon != "") {
              freeShipCoupon.push(coupon);
            }
            return true;
          } else {
            alert("每个订单只可以使用一次免邮券");
            return false;
          }
      }
    };
    this.cancelCouponVerify = function(favorableORfreeShip, coupon) {
      switch (favorableORfreeShip) {
        case "favorableCoupon" :
          if (!_this.getCouponVerify("favorableCoupon")) {
            favorableCoupon = [];
            break;
          } else {
            console.error("你favorableCoupon为空,点击使用时未加入");
            break;
          }
        case "freeShipCoupon" :
          if (!_this.getCouponVerify("freeShipCoupon")) {

            freeShipCoupon = [];
            break;
          } else {
            console.error("你的freeShipCoupon为空,点击使用时未加入");
            break;
          }
      }
    }
  }

//事件的聚合器
  function EventController(orderAmountByCoupon, eventAggregator, chooseTicketVerify) {

    var $pageindex = $('#pageindex');
    if($pageindex.length == 0) {
      $('#js_selet_coupon').prepend('<div class="coupon_bd" style="margin-bottom: 10px"><input class="text" type="text" value=1 id="pageindex" placeholder="分页数"><input class="btn" type="button" id="btnLoadCoupon" value="查询"></div>');
      $('#js_coupon_change_btn').css('top', 111);

      $('#btnLoadCoupon').on('click',function() {
        productRepository = new ProductRepositoryFix(chooseTicketVerify, $('#pageindex').val());
      });
    }


    $("#couponCardNo").on("blur", function() {
      if ($("#couponCardNo").val() == '') {
        $("#couponCardNo").val("请输入优惠券码");
      }
    }).on("focus", function() {
      $("#couponCardNo").val("");
    });
//-----------------------------------------------------------------------------            
    eventAggregator.subscribe("couponUsed", function(eventArgs) {
      var coupon = eventArgs.coupon[0];
      if (chooseTicketVerify.chooseCouponVerify("favorableCoupon", coupon)) {
        $("#coupon_message").html('<span>已选优惠券：' + coupon.cardNo() + '，优惠额度：' + coupon.canUseAmount() + '元。</span>');
        /* 计算使用优惠券 开始 */
        //couponType:0 优惠劵 2 礼品卡 4 免邮劵;operationType:10:使用   20:取消使用
        var couponList = [];
        var couponItem = {
          couponNo: coupon.cardNo(),
          couponBatchId: coupon.couponBatchId(),
          useAmount: coupon.canUseAmount()
        };
        couponList.push(couponItem);
        var couponJsonStr = {
          couponList: couponList,
          operationType: 10
        };
        orderAmountByCoupon.getCouponUseState(couponJsonStr, true, coupon.couponUsebutton(), coupon.couponUnusebutton(), coupon.couponSelectedli(), coupon.couponSelectedli(), "");
      }
    });
    eventAggregator.subscribe("freeShipCouponUsed", function(eventArgs) {
      var coupon = eventArgs.FreeShipCoupon[0];
      if (chooseTicketVerify.chooseCouponVerify("freeShipCoupon", coupon)) {
        $("#freeshop_coupon_message").html('<span>已选免邮券：' + coupon.cardNo() + '，抵用当前运费。</span>');
        /* 计算使用免邮券 开始 */
        //couponType:0 优惠劵 2 礼品卡 4 免邮劵;operationType:10:使用   20:取消使用
        var cardDetail = [];
        var couponItem = {
          cardNo: coupon.cardNo(),
          cardBatchId: coupon.couponBatchId(),
        };
        cardDetail.push(couponItem);
        var freeFreightCardJsonStr = {
          cardDetail: cardDetail,
          useAmount: 0,
          useNum: 1,
          operationType: 10
        };
        orderAmountByCoupon.getFreeShipCouponUseState(freeFreightCardJsonStr, true, coupon.freeShipUsebutton(), coupon.freeShipUnusebutton(), coupon.freeShipSelectedli(), coupon.freeShipSelectedli(), "");
      }
    });
    eventAggregator.subscribe("cancelCouponList", function(eventArgs) {
      var coupon = eventArgs.cancelCoupon[0];
      $("#coupon_message").empty();
      /* 列表取消使用优惠券 开始 */
      //couponType:0 优惠劵 2 礼品卡 4 免邮劵;operationType:10:使用   20:取消使用
      var couponList = null;
      var couponJsonStr = {
        couponList: couponList,
        operationType: 20
      };
      orderAmountByCoupon.getCouponUseState(couponJsonStr, false, coupon.couponUsebutton(), coupon.couponUnusebutton(), coupon.couponSelectedli(), coupon.couponSelectedli(), "list");
      chooseTicketVerify.cancelCouponVerify("favorableCoupon", coupon);
    });
    eventAggregator.subscribe("cancelFreeShipCouponList", function(eventArgs) {
      var coupon = eventArgs.cancelFreeShipCoupon[0];
      $("#freeshop_coupon_message").empty();
      /* 列表取消使用免邮券 开始 */
      //couponType:0 优惠劵 2 礼品卡 4 免邮劵;operationType:10:使用   20:取消使用
      var cardDetail = null;
      var freeFreightCardJsonStr = {
        cardDetail: cardDetail,
        useAmount: 0,
        useNum: 0,
        operationType: 20
      };
      orderAmountByCoupon.getFreeShipCouponUseState(freeFreightCardJsonStr, false, coupon.freeShipUsebutton(), coupon.freeShipUnusebutton(), coupon.freeShipSelectedli(), coupon.freeShipSelectedli(), "list");
      chooseTicketVerify.cancelCouponVerify("freeShipCoupon", coupon);
    });
    eventAggregator.subscribe("cancelCouponTips", function(eventArgs) {
      /* 提示信息取消使用优惠券 */
      var coupon = eventArgs.cancelCoupon[0];
      var couponList = null;
      var couponJsonStr = {
        couponList: couponList,
        operationType: 20
      };
      orderAmountByCoupon.getCouponUseState(couponJsonStr, false, coupon.couponUsebutton(), coupon.couponUnusebutton(), coupon.couponSelectedli(), coupon.couponSelectedli(), "div");
      chooseTicketVerify.cancelCouponVerify("favorableCoupon", coupon);
      $("#coupon_message").empty();
    });
    eventAggregator.subscribe("cancelFreeShipCouponTips", function(eventArgs) {
      /* 提示信息取消使用免邮券 */
      var coupon = eventArgs.cancelFreeShipCoupon[0];
      var couponList = null;
      var couponJsonStr = {
        couponList: couponList,
        operationType: 20
      };
      orderAmountByCoupon.getFreeShipCouponUseState(couponJsonStr, false, coupon.freeShipUsebutton(), coupon.freeShipUnusebutton(), coupon.freeShipSelectedli(), coupon.freeShipSelectedli(), "div");
      chooseTicketVerify.cancelCouponVerify("freeShipCoupon", coupon);
      $("#freeshop_coupon_message").empty();
    });
    eventAggregator.subscribe("titleButtonClick", function() {
      //加减号按钮
      if ($("#js_syyhq_btn").children("div").attr("class").split(" ").indexOf("red_jiahao") != -1) {
        $("#js_selet_coupon").removeClass("hidden");
        $("#help_coupon").removeClass("hidden");
        $("#js_syyhq_btn").children("div").removeClass("red_jiahao").addClass("red_jianhao");
        if ($("#coupon_message").html() != "") {
          $("#js_selected_coupon").addClass("hidden");
        }
        if ($("#freeshop_coupon_message").html() != "") {
          $("#js_selected_freeshop_coupon").addClass("hidden");
        }
      } else {
        $("#js_selet_coupon").addClass("hidden");
        $("#help_coupon").addClass("hidden");
        $("#js_syyhq_btn").children("div").addClass("red_jiahao").removeClass("red_jianhao");
        if ($("#coupon_message").html() != "") {
          $("#js_selected_coupon").removeClass("hidden");
        }
        if ($("#freeshop_coupon_message").html() != "") {
          $("#js_selected_freeshop_coupon").removeClass("hidden");
        }
      }
    });
    eventAggregator.subscribe("bindingInputCoupon", function(eventArgs) {
      /* input绑定券 */
      var cardNo = $("#couponCardNo").val();
      if (cardNo) {
        if (cardNo == '请输入优惠券码') {
          alert("请输入优惠券码");
          return;
        }
        var params = "cardNo=" + cardNo;
        Js.sendData(sendLink.tradeservice + ORDER.API.bindingCoupon, params, function(data) {
          //绑定优惠券按钮服务响应结果处理
          if (data.status == '0') {
            alert("绑定成功");
            $("#couponCardNo").val("");
            productRepository = new ProductRepository(chooseTicketVerify, "");
          } else {
            if (data.message.indexOf("调用dubbo") != -1) {
              alert("绑定失败，请稍后再试！");
            } else {
              alert(data.message);
            }
            return;
          }
        });
      }
    });
//优惠券免邮券切换
    eventAggregator.subscribe("switchHeadlineClickFun", function(favorableORfreeShip) {
      switch (favorableORfreeShip) {
        case"favorableCoupon" :
          $("#common_coupon_list").removeClass("hidden");
          $("#freeship_coupon_list").addClass("hidden");
          //将点击项改为选中样式，非点击项删除选中
          $("#freeship_coupon_btn_tab").removeClass("cur");
          $("#coupon_btn_tab").addClass("cur");
          break;
        case"freeShipCoupon" :
          $("#common_coupon_list").addClass("hidden");
          $("#freeship_coupon_list").removeClass("hidden");
          //将点击项改为选中样式，非点击项删除选中
          $("#freeship_coupon_btn_tab").addClass("cur");
          $("#coupon_btn_tab").removeClass("cur");
          break;
      }
    });
    eventAggregator.subscribe("switchUseOrUnuseButton", function(UseOrUnuse) {
      switch (UseOrUnuse) {
        case"useCoupon" :
          $("#coupon_no_apply_btn").removeClass("cur");
          $("#coupon_yes_apply_btn").addClass("cur");
          $("#js_coupon_yes_list").removeClass("hidden");
          $("#js_coupon_no_list").addClass("hidden");
          $("#js_coupon_click").text("可用优惠券");
          break;
        case"unUseCoupon" :
          $("#coupon_yes_apply_btn").removeClass("cur");
          $("#coupon_no_apply_btn").addClass("cur");
          $("#js_coupon_no_list").removeClass("hidden");
          $("#js_coupon_yes_list").addClass("hidden");
          $("#js_coupon_click").text("不可用优惠券");
          break;
        case"useFreeShip" :
          $("#freeship_coupon_no_apply_btn").removeClass("cur");
          $("#freeship_coupon_yes_apply_btn").addClass("cur");
          $("#js_freeship_coupon_yes_list").removeClass("hidden");
          $("#js_freeship_coupon_no_list").addClass("hidden");
          $("#js_freeship_coupon_click").text("可用免邮券");
          break;
        case"unUseFreeShip" :
          $("#freeship_coupon_yes_apply_btn").removeClass("cur");
          $("#freeship_coupon_no_apply_btn").addClass("cur");
          $("#js_freeship_coupon_no_list").removeClass("hidden");
          $("#js_freeship_coupon_yes_list").addClass("hidden");
          $("#js_freeship_coupon_click").text("不可用免邮券");
          break;
      }
    })
  }


  var showYesCouponList = function(couponData) {

    var html =  '<ul>\
    <input type="hidden" id="haveUsedFlag"></input>' ;

  if(couponData != null ){
    for(var i = 0; i < couponData.length; i ++){
      var couponItem = couponData[i];
      var startD = couponItem.useStartDate().substring(0,10);
      var endD = couponItem.useEndDate().substring(0,10);
      var dataString = startD+"～"+endD;

      html += '<li class="clearfix" id="li_coupon_'+couponItem.cardNo()+'">\
        <div class="coupon_icon"><div class="sale_icon"><span>满减券</span></div></div>\
        <div class="coupon_name"><div class="coupon_text text_name"><span>'+couponItem.cardName()+'</span></div></div>\
        <div class="coupon_num"><div class="coupon_text"><span>'+couponItem.cardNo()+'</span></div></div>\
        <div class="coupon_money"><div class="coupon_text"><span>￥'+couponItem.cash()+'</span></div></div>\
        <div class="coupon_time"><div class="coupon_text"><span>'+dataString+'</span></div></div>\
        <div class="coupon_btn">\
        <div class="btn use_btn"  id="use_selected_coupon_'+couponItem.cardNo()+'"><a href="javascript:void(0)" onclick="ORDER.CouponModuleFix.onCouponSelected(this)"><span>使用</span></a></div>\
        <div class="btn cancel_btn dead_colour hidden" id="unuse_selected_coupon_'+couponItem.cardNo()+'"><a href="javascript:void(0);"onclick="ORDER.CouponModuleFix.onCancelCouponList(this)"><span>取消使用</span></a></div>\
        <div class="coupon_tips hidden" id="right_tips_'+couponItem.cardNo()+'">\
        <div class="sanjiao"></div>\
        <span>优惠券每次只可以使用一张哦~</span>\
      </div>\
      </div>\
      </li>';

    }
  }

  html += '</ul>';
  return html;
  };

  function ProductRepositoryFix(chooseTicketVerify, pageindex) {

    var params = 'status=2&type=1&start='+pageindex+'&rows=10';
    var couponData = [], couponNoData = [], freeShipCouponData = [], freeShipCouponNoData = [];
    Js.sendData('http://tradeservice.lemall.com/api/coupon/v1/memberQueryCouponByStatus.jsonp', params, function(data) {
      if (data.status == '0') {
        //可用商品优惠券列表
        if (data.result.length > 0) {
          couponData = [];
          for (var i = 0; i < data.result.length; i++) {
            var coupon = data.result[i];
            coupon.canUseAmount = coupon.cash|| 0;//可用金额
            // isAgreeFlag="true" 可用，isAgreeFlag="false"不可用
            couponData.push(new Product(coupon.cardNo, coupon.cardName, coupon.useStartDate, coupon.useEndDate, coupon.useQuota, coupon.couponBatchId, coupon.cash, coupon.canUseAmount));
          }
        }

        couponPageShow(couponData, couponNoData);
      }
    });

//-----------------------------------------------
    this.getCouponData = function() {
      return couponData;
    };
    this.getCouponNoData = function() {
      return couponNoData;
    };
    this.getFreeShipCouponData = function() {
      return freeShipCouponData;
    };
    this.getFreeShipCouponNoData = function() {
      return freeShipCouponNoData;
    };
//------------------------------------------------
    function couponPageShow(couponData, couponNoData) {
      // 可使用优惠券列表
      if (couponData.length > 0) {
        //var couponData = {couponData: couponData};
        var data = showYesCouponList( couponData);

        $("#js_coupon_yes_list").empty().append(data);
      }
      // 不可使用优惠券列表
      if (couponNoData.length > 0) {
        var couponNoData = {couponNoData: couponNoData};
        var data = Js.Tools.template("showNoCouponList", couponNoData)
        $("#js_coupon_no_list").empty().append(data);
      }
      if (!chooseTicketVerify.getCouponVerify("favorableCoupon")) {
        var chooseCouponData = chooseTicketVerify.getChooseCouponData();
        var cardNo = chooseCouponData.favorableCoupon[0].cardNo();
        chooseTicketVerify.cancelCouponVerify('favorableCoupon', chooseCouponData.favorableCoupon[0]);
        $("#use_selected_coupon_" + cardNo).find('a').click();
      }
    }

  }

//-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -
//主要是发布触发事件
  return {
    //选取优惠券
    onCouponSelected: function(e) {
      var getCouponData = productRepository.getCouponData();
      var couponId = $(e).parent().attr('id');
      var coupon = $.grep(getCouponData, function(x) {
        //console.log(x, couponId)
        return x.couponUsebutton() == couponId
      })
     //console.log(getCouponData, coupon)
      eventAggregator.publish("couponUsed", {coupon: coupon});
    },
    //选取免邮券
    onFreeShipCouponSelected: function(e) {
      var getFreeShipCouponData = productRepository.getFreeShipCouponData();
      var FreeShipId = $(e).parent().attr('id');
      var FreeShipCoupon = $.grep(getFreeShipCouponData, function(x) {
        return x.freeShipUsebutton() == FreeShipId
      });
      eventAggregator.publish("freeShipCouponUsed", {FreeShipCoupon: FreeShipCoupon})
    },
    //从列表取消优惠券
    onCancelCouponList: function(e) {
      var getCouponData = productRepository.getCouponData();
      var couponUnuseId = $(e).parent().attr('id');
      var cancelCoupon = $.grep(getCouponData, function(x) {
        return x.couponUnusebutton() == couponUnuseId
      });
      eventAggregator.publish("cancelCouponList", {cancelCoupon: cancelCoupon})
    },
    //从列表取消免邮券
    onCancelFreeShipCouponList: function(e) {
      var getFreeShipCouponData = productRepository.getFreeShipCouponData();
      var freeShipUnuseId = $(e).parent().attr('id');
      var cancelFreeShipCoupon = $.grep(getFreeShipCouponData, function(x) {
        return x.freeShipUnusebutton() == freeShipUnuseId
      });
      eventAggregator.publish("cancelFreeShipCouponList", {cancelFreeShipCoupon: cancelFreeShipCoupon})
    },
    //从提示信息处取消优惠券
    onCancelCouponTips: function() {
      var getCouponData = productRepository.getCouponData();
      var couponCardNo = $("#coupon_message").html().split("：")[1].split("，")[0];
      var cancelCoupon = $.grep(getCouponData, function(x) {
        return x.cardNo() == couponCardNo;
      });
      eventAggregator.publish("cancelCouponTips", {cancelCoupon: cancelCoupon})
    },
    //从提示信息处取消免邮券
    onCancelFreeShipCouponTips: function() {
      var getFreeShipCouponData = productRepository.getFreeShipCouponData();
      var freeShipCardNo = $("#freeshop_coupon_message").html().split("：")[1].split("，")[0];
      var cancelFreeShipCoupon = $.grep(getFreeShipCouponData, function(x) {
        return x.cardNo() == freeShipCardNo;
      });
      eventAggregator.publish("cancelFreeShipCouponTips", {cancelFreeShipCoupon: cancelFreeShipCoupon})
    },
    //title键点击
    onTitleButtonClick: function() {
      eventAggregator.publish("titleButtonClick", "");
    },
    //绑定input券
    onInputButtonClick: function() {
      eventAggregator.publish("bindingInputCoupon", "");
    },
    //绑定优惠券免邮券按钮切换事件                                switchHeadlineClickFun
    onSwitchHeadlineClick: function(e) {
      eventAggregator.publish("switchHeadlineClickFun", e);
    },
    //切换可用不可用列表
    onSwitchUseOrUnuseButton: function(e) {
      eventAggregator.publish("switchUseOrUnuseButton", e);
    }
  };
}()